import {
    searchMusicScore
} from '../../../config/api'
import * as actionTypes from './actionTypes';
import { localStorageTool } from '../../../config/utils';

// 操作 修改搜索文本
export const operateChangeText = (data) => ({
	type: actionTypes.Operate_Change_Text,
	data
});
// 操作 删除搜索文本
export const operateDeleteText = () => ({
	type: actionTypes.Operate_Delete_Text
});
// 操作 确定搜索文本
export const operateConfirmText = (data) => ({
	type: actionTypes.Operate_Confirm_Text,
	data
})
// 操作 选择标签
export const operateSelectLabel = (data) => ({
	type: actionTypes.Operate_Select_Label,
	data
})
// 操作 清空历史
export const operateEmptyHistory = () => ({
	type: actionTypes.Operate_Empty_History
})

// 搜索 特定 曲谱
export const searchDefiniteScore = (searchText, page, open_id, union_id) => {
	console.log(searchText, page, open_id, union_id)
	return async (dispatch) => {
		const resultInfo = await searchMusicScore(searchText, page, open_id, union_id)
		if (resultInfo.status === 200) {
			localStorageTool('writeArray', 'scoreInfo', searchText, 25)
			dispatch(operateConfirmText(resultInfo.data));
		}
	}
};
